//	var API_DOMAIN = 'http://172.25.253.192:86/'
		var API_DOMAIN = '/'

			
			
			Array.prototype.forEach = Array.prototype.forEach || function (callback) {
	        var isArray = Object.prototype.toString.call(this) == '[object Array]';
	        if(isArray){
	            for(var key in this){
	                if(key != 'forEach'){
	                    callback.call(this[key],key,this[key],this);
	                }
	            }
	        }else{
	            throw TypeError;
	        }
	};

NodeList.prototype.forEach = Array.prototype.forEach;		


var areasArray =new Array(
    '<option value="370102">历下区</option>',
    '<option value="370103">市中区</option>',
    '<option value="370104">槐荫区</option>',
    '<option value="370105">天桥区</option>',
    '<option value="370112">历城区</option>',
    '<option value="370113">长清区</option>',
    '<option value="370124">平阴县</option>',
    '<option value="370125">济阳县</option>',
    '<option value="370126">商河县</option>',
    '<option value="370181">章丘市</option>',
    '<option value="370182">高新区</option>' );
    
    
/**
 * ajax请求封装
 * @param options
 */
var request = function (options) {

  if(!options.xhrFields) {
    options.xhrFields = {
      withCredentials: true
    }
  }

  if(!options.crossDomain) {
    //options.crossDomain = true
  }

  if(!options.method) {
    options.method = 'POST'
  }

  if(!options.headers){
    options.headers = {
      'X-Requested-With': 'XMLHttpRequest',
      'content-type': 'application/x-www-form-urlencoded;charset=utf-8'
    }
  }

  $.ajax(options)
}

var setUserInfoHeader = function (callback) {
  getUserInfo(function (userdata) {
    document.getElementById('header-username').innerHTML = '<img src="/static/img/user.png" alt=""><a id="header-username">'+userdata.authUser.account+'</a>';
    if (typeof callback == 'function'){
      callback(userdata);
    }
  })
}

var getUserInfo = function (callback) {
  // 获取当前用户信息
  request({
    url: API_DOMAIN + 'culture/cultrueUser/loadCultrueUser',
    success: function (result) {
      if(result.statusCode === 200){
        callback(result.data);
      } else {
        window.location.href = '/login.html';
      }
    }
  })
};

/**
 * 上传文件
 * @param options
 */
var requestFile = function (options) {
  if(!options.xhrFields) {
    options.xhrFields = {
      withCredentials: true
    }
  }

  if(!options.crossDomain) {
    options.crossDomain = true
  }

  options.method = 'POST'
  options.contentType = false;
  options.processData = false,

  $.ajax(options)
}

var modalError = function (message) {
  alert(message);
}

function doLogout(){
  request({
    url: API_DOMAIN + "api/auth/logout",
    success: function (data) {
      if(data.statusCode === 200){
        window.location.href = '/login.html'
      }
    }
  })
}

/**
 * 跳转页面
 * @param url
 */
var goUrl = function (url) {
  window.location.href = url
}


var getUrlParam = function(variable){
  var query = window.location.search.substring(1);
  var vars = query.split("&");
  for (var i=0;i<vars.length;i++) {
          var pair = vars[i].split("=");
          if(pair[0] == variable){return pair[1];}
  }
  return(false);
}

// 获取项目类型名
function getTypeName(value) {
	  switch (value) {
	    case 1:
	      return '新闻信息服务';
	      break;
	    case 2:
	      return '内容创作生产';
	      break;
	    case 3:
	      return '创意设计服务';
	      break;
	    case 4:
	      return '文化传播渠道';
	      break;
	    case 5:
	      return '文化投资运营';
	      break;
	    case 6:
	      return '文化娱乐休闲服务';
	      break;
	    case 7:
	      return '文化辅助生产和中介服务';
	      break;
	    case 8:
	      return '文化消费终端生产';
	      break;
	    case 9:
	      return '文化消费终端生产';
	    case 99:
	      return '其他';
	      break;
	    default:
	      return '未知';
	      break;
	  }
}


function checkNum(input){
	var reg=/^[0-9]+.?[0-9]*$/; //判断字符串是否为数字 ，判断正整数用/^[1-9]+[0-9]*]*$/
	if(!reg.test(input)){
	    return false;
	 }
	return true;
}